<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
$(function(){
	$("#electricityPrice").textbox('setValue','1.0');
	$("#waterPrice").textbox('setValue','2.0');
	$("#years").textbox('setValue',doHandleDateYears());
	$("#month").textbox('setValue',doHandleDateMonth());
	
	$("#combinedButton").click(function(){
		var water = $("#water").val();
		var electricity = $("#electricity").val();
		var waterPrice = $("#waterPrice").val();
		var electricityPrice = $("#electricityPrice").val();
		var combined = water*waterPrice+electricity*electricityPrice;
		$("#combined").textbox('setValue',combined);
	});
	
	$("#saveButton").click(function(){
		var storiedBuilding = $("#storiedBuilding").val();
		var dormitory = $("#dormitory").val();
		var water = Number($("#water").val());
		var electricity = Number($("#electricity").val());
		var waterPrice = Number($("#waterPrice").val());
		var electricityPrice = Number($("#electricityPrice").val());
		var combined = water*waterPrice+electricity*electricityPrice;
		var status = $("#status").combobox('getValue');
		var years = $("#years").val();
		var month = $("#month").val();
		if(storiedBuilding!="" && dormitory!="" && water!="" && electricity!="" && waterPrice!="" && electricityPrice!="" && combined!="" && status!="" && years!="" && month!=""){
			$.ajax({
				type:'POST',
				url:'waterElectricityAddData.action',
				data:{storiedBuilding:storiedBuilding,water:water,electricity:electricity,waterPrice:waterPrice,electricityPrice:electricityPrice,combined:combined,dormitory:dormitory,status:status,years:years,month:month},//
				datatype:'json',
				success:function(msg){
					if(msg.status=="200"){
						parent.closeDialog();
					}else{
						$.messager.alert("提示","保存失败");
					}
				}
			});
		}else{
			$.messager.alert("提示","表单信息不完整");
		}
	});
	
});


function doHandleDateYears() {
    var myDate = new Date();
    var tYear = myDate.getFullYear();
    var tMonth = myDate.getMonth();
 
    var m = tMonth + 1;
    if (m.toString().length == 1) {
        m = "0" + m;
    }
    return tYear;
}

function doHandleDateMonth() {
    var myDate = new Date();
    var tYear = myDate.getFullYear();
    var tMonth = myDate.getMonth();
 
    var m = tMonth + 1;
    if (m.toString().length == 1) {
        m = "0" + m;
    }
    return m;
}

function doHandleYear(tYear) {
    var myDate = new Date();
    var tYear = myDate.getFullYear();
 
    return tYear;
}
function doHandleMonth() {
    var myDate = new Date();
    var tMonth = myDate.getMonth();
 
    var m = tMonth + 1;
    if (m.toString().length == 1) {
        m = "0" + m;
    }
    return m;
}